import { setToken, getToken } from '@/untils/setToken'
import store from './store'
import router from './router/index'
import service from './service/index'
router.beforeEach(async (to, from, next) => {

    if (!to.query.st && to.params.id) {
        if (getToken('token')) {
            // debugger
            store.commit('user/update_act_id', to.params.id)
            const res = await service.GetData()
            //res.data.temp_style = 5
            if (!res.data || !res.data.temp_style) {
                next('/404')
            }
            if (res.data.temp_style == 1) {
                if (to.fullPath == `/${to.params.id}`) {
                    next()
                } else {
                    next({ path: `/${to.params.id}` })
                }
            } else if (res.data.temp_style == 2) {
                if (to.fullPath == `/index2/${to.params.id}`) {
                    next()
                } else {
                    next({ path: `/index2/${to.params.id}` })
                }
            } else if (res.data.temp_style == 3) {
                if (to.fullPath == `/index3/${to.params.id}`) {
                    next()
                } else {
                    next({ path: `/index3/${to.params.id}` })
                }
            } else if (res.data.temp_style == 4) {
                if (to.fullPath == `/index4/${to.params.id}`) {
                    next()
                } else {
                    next({ path: `/index4/${to.params.id}` })
                }
            } else if (res.data.temp_style == 5) {
                if (to.fullPath == `/index5/${to.params.id}`) {
                    next()
                } else {
                    next({ path: `/index5/${to.params.id}` })
                }
            } else {
                next('/404')
            }




        } else {
            window.location.href = `https://olpassport.5211game.com/Login?siteid=50008&returnUrl=${escape(window.location.href)}&srvid=7`
        }
    } else if (to.query.st && to.params.id) {
        debugger
        setToken('token', to.query.st)
        store.commit('user/update_st', to.query.st)
        store.commit('user/update_act_id', to.params.id)
        const res = await service.GetData()
        if (!res.data || !res.data.temp_style) {
            next('/404')
        }
        if (res.data.temp_style == 1) {

            next({ path: `/${to.params.id}` })

        } else if (res.data.temp_style == 2) {

            next({ path: `/index2/${to.params.id}` })
        } else if (res.data.temp_style == 3) {

            next({ path: `/index3/${to.params.id}` })
        } else if (res.data.temp_style == 4) {

            next({ path: `/index4/${to.params.id}` })
        } else if (res.data.temp_style == 5) {

            next({ path: `/index5/${to.params.id}` })
        } else {
            next({ path: `/${to.params.id}` })
        }

    } else {
        window.location = "https://www.5211game.com"
    }
})